var App = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageSize:10,
    list:[],
    page:1,// 当前页码
    last_page:1,
    scrollHeight: null,
    no_more: false, // 没有更多数据
    isLoading: true, // 是否正在加载中
    isScrollAble:true,
    refreshOpen:true, //下拉刷新/下拉复位
    refreshstatus:true, //是否开启下拉刷新
    card_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.card_id != undefined){
      this.setData({
        card_id:options.card_id
      })
    }
    this.setListHeight()
    this.setData({
      isLogin: App.checkIsLogin(),
      page:1,// 当前页码
      last_page:1,
      no_more: false, // 没有更多数据
      isLoading: true, // 是否正在加载中
    });
    // 获取数据列表
    this.getDataList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  
  //获取数据列表
  getDataList(isPage, page){
    let that = this;
    let obj = {
      card_id:that.data.card_id,
      page: page || 1,
      pageSize:that.data.pageSize,
    }
    App.request('/Manage/Management/memberWashingLog',obj,function(e){
       // 刷新状态复位
       that.setData({refreshOpen: 0 });
        // 不加这个方法真机下拉会一直处于刷新状态，无法复位
        if (e.code == "200") {
          let resList = e.result,dataList = that.data.list;
          if (isPage == true) {
            that.setData({
              list:dataList.concat(resList.data),
              isLoading: false,
              last_page: resList.total,
            })
          }else{
            that.setData({
              list: resList.data,
              isLoading: false,
              last_page: resList.total,
              delTips :resList.delTips,
              settleTips :resList.settleTips,
              start_date :resList.start_date,
              end_date :resList.end_date,
            })
          }
        } else {
          wx.showToast({
            title: e.message,
            icon: 'none',
            duration: 2000
          })
        }
    })
  },
  // 删除记录
  delete: function (e){
    let that = this;
    let obj = {order_id:e.currentTarget.dataset.id}
    wx.showModal({
      title: "提示",
      content: that.data.delTips,
      success(e) {
        if(e.confirm == true){
          App.request('/Manage/Management/washingDel',obj,function(e){
            if (e.code == "200") {
              App.showSuccessToast(e.msg);
            } 
          })
        }
      }
    });
    
  },
  // 强制结算
  leave: function (e){
    let that = this;
    let obj = {site_id:e.currentTarget.dataset.id}
    wx.showModal({
      title: "提示",
      content: that.data.settleTips,
      success(e) {
        if(e.confirm == true){
          App.request('/Manage/Management/forceSettle',obj,function(e){
            if (e.code == "200") {
              App.showSuccessToast(e.msg);
            } 
          })
        }
      }
    });
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
  // 自定义下拉刷新
  upRefresh(){
    this.setData({
      list:[],
      page:1,// 当前页码
      last_page:1,
      no_more: false, // 没有更多数据
      isLoading: true, // 是否正在加载中
    })
    this.getDataList()
  },
   /**
   * 下拉到底加载数据
   */
  bindDownLoad() {
    // 已经是最后一页
    console.log("翻页");
    console.log("page =",this.data.page)
    console.log("last_page =",this.data.last_page)
    if (this.data.page > this.data.last_page) {
      this.setData({
        no_more: true
      });
      return false;
    }
    // 加载下一页列表
    this.getDataList(true, ++this.data.page);
  },
  /**
   * 设置文章列表高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 20), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
      console.log(systemInfo.windowHeight,scrollHeight);
      this.setData({
        scrollHeight
      });
  },
  
})